﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using mesoBoard.Data;
using mesoBoard.Services;
using mesoBoard.Web.Core;

namespace mesoBoard.Web.Areas.Admin.Controllers
{
    public class UsersController : mesoBoardAdminController
    {
        public ActionResult ChangeUserStatus(int UserID)
        {
            User TheUser = Repositories.Users.GetUser(UserID);
            if (string.IsNullOrEmpty(TheUser.ActivationCode))
            {
                TheUser.ActivationCode = Randoms.CleanGUID();
                SetSuccess("User deactivated");
            }
            else
            {
                TheUser.ActivationCode = string.Empty;
                SetSuccess("User activated");
            }
            Repositories.Users.UpdateUser(TheUser);
            return RedirectToAction("UserDetails", new { UserID = UserID });
        }

        public ActionResult Users()
        {
            SetCrumb("Users");
            return View(Repositories.Users.GetAllUsers());
        }

        public ActionResult UserDetails(int UserID)
        {
            SetCrumb("Users");
            User TheUser = Repositories.Users.GetUser(UserID);
            return View(TheUser);
        }

        public ActionResult DeleteUser(int UserID)
        {
            Repositories.Users.DeleteUser(UserID);
            SetSuccess("User deleted");
            return RedirectToAction("Users");
        }
    }
}
